package com.thrift.server.annotation;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author 何锦涛--CodeSleep
 * @since 2022/9/11 20:32
 */
@Component
public class ThriftRunner implements ApplicationRunner {

    private static final Logger logger = LoggerFactory.getLogger(ThriftRunner.class);

    @Override
    public void run(ApplicationArguments args) throws Exception {
        Map<Integer, Map<String, Object>> serviceMap = ThriftServerPostProcess.serviceMap;
        // 多线程启动服务
        for (Integer key : serviceMap.keySet()) {
            ServeThread thread = new ServeThread(key, serviceMap.get(key));
            thread.setName("Thrift-server-" + key);
            thread.start();
            logger.info("多线程启动 Thrift Server {}", Thread.currentThread().getName());
        }
    }
}
